<?php

if (!defined('BASEPATH'))
    exit('No Direct Script access allowed');

class All extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->library('encrypt');
    }

    function login($log) {
        $this->db->where('id', $log['id']);
        $this->db->where('password', $log['password']);
        $data = $this->db->get('user');
        if ($data->num_rows == 1) {
            return $data->row();
        } else {
            return FALSE;
        }
    }

    function username($id) {
        $this->db->where('id', $id['id']);
        $username = $this->db->get('user');
        if ($username->num_rows > 0) {
            return $username->result();
        }
    }

    function social() {
        $data = $this->db->get('social');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function edit_social($facebook, $twitter) {
        $this->db->where('id', 1);
        $this->db->update('social', $facebook);
        $this->db->where('id', 2);
        $this->db->update('social', $twitter);
    }

    function get_thn() {
        $get = $this->db->get('tahun');
        if ($get->num_rows > 0) {
            return $get->num_rows();
        }
    }

    function get_tahun() {
        $get = $this->db->get('tahun');
        if ($get->num_rows > 0) {
            return $get->result();
        }
    }

    function tahun($config) {
        $this->db->order_by('thn', 'asc');
        $get = $this->db->get('tahun', $config['per_page'], $config['uri']);
        if ($get->num_rows > 0) {
            return $get->result();
        }
    }

    function get_id_thn($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('tahun');
        return $query->result();
    }

    function add_thn($input) {
        $this->db->insert('tahun', $input);
    }

    function upd_thn($data) {
        $this->db->where('id', $data['id']);
        $this->db->update('tahun', $data);
    }

    function del_thn($dwe) {
        $this->db->where('id', $dwe);
        $this->db->delete('tahun');
    }

    function semester() {
        $res = $this->db->get('semester');
        if ($res->num_rows > 0) {
            return $res->result();
        }
    }

    function con_smstr() {
        $smstr = $this->db->get('semester');
        if ($smstr->num_rows > 0) {
            return $smstr->num_rows;
        }
    }

    function get_id_semester($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('semester');
        return $query->result();
    }

    function add_semester($input) {
        $this->db->insert('semester', $input);
    }

    function upd_semester($smstr) {
        $this->db->where('id', $smstr['id']);
        $this->db->update('semester', $smstr);
    }

    function del_semester($id) {
        $this->db->where('id', $id);
        $this->db->delete('semester');
    }

    function hari() {
        $this->db->order_by('id', 'asc');
        $res = $this->db->get('hari');
        if ($res->num_rows > 0) {
            return $res->result();
        }
    }

    function get_id_hari($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('hari');
        return $query->result();
    }

    function upd_hari($harii) {
        $this->db->where('id', $harii['id']);
        $this->db->update('hari', $harii);
    }

    function add_hari($input) {
        $this->db->insert('hari', $input);
    }

    function del_hari($id) {
        $this->db->where('id', $id);
        $this->db->delete('hari');
    }

    function jampel() {
        $res = $this->db->get('jam');
        if ($res->num_rows > 0) {
            return $res->result();
        }
    }

    function get_id_jam($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('jam');
        return $query->result();
    }

    function add_jampel($input) {
        $this->db->insert('jam', $input);
    }

    function upd_jam($data) {
        $this->db->where('id', $data['id']);
        $this->db->update('jam', $data);
    }

    function del_jam($id) {
        $this->db->where('id', $id);
        $this->db->delete('jam');
    }

    function kelas() {
        $res = $this->db->get('kelas');
        if ($res->num_rows > 0) {
            return $res->result();
        }
    }

    function get_id_kelas($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('kelas');
        return $query->result();
    }

    function add_kelas($input) {
        $this->db->insert('kelas', $input);
    }

    function upd_kelas($input) {
        $this->db->where('id', $input['id']);
        $this->db->update('kelas', $input);
    }

    function del_kelas($id) {
        $this->db->where('id', $id);
        $this->db->delete('kelas');
    }

    function mapel() {
        $this->db->order_by('id', 'asc');
        $res = $this->db->get('mapel');
        if ($res->num_rows > 0) {
            return $res->result();
        }
    }

    function get_id_mapel($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('mapel');
        return $query->result();
    }

    function add_mapel($input) {
        $this->db->insert('mapel', $input);
    }

    function upd_mapel($input) {
        $this->db->where('id', $input['id']);
        $this->db->update('mapel', $input);
    }

    function del_mapel($id) {
        $this->db->where('id', $id);
        $this->db->delete('mapel');
    }

    function jadwal() {
        $res = $this->db->get('jadwal');
        if ($res->num_rows > 0) {
            return $res->result_array();
        }
    }

    function add_jadwal($input) {
        $this->db->insert('jadwal', $input);
    }

    function del_jadwal($id) {
        $this->db->where('id', $id);
        $this->db->delete('jadwal');
    }

    function user() {
        $this->db->where('akses', 'Staff');
        $res = $this->db->get('vuser_det');
        if ($res->num_rows > 0) {
            return $res->result();
        }
    }

    function get_user_id($id) {
        $this->db->where('id', $id);
        $res = $this->db->get('vuser_det');
        if ($res->num_rows > 0) {
            return $res->result();
        }
    }

    function add_user($input) {
        $this->db->insert('user', $input);
    }

    function upd_user($user) {
        $this->db->where('id', $user['id']);
        $this->db->update('user', $user);
    }

    function del_user($id) {
        $this->db->where('id', $id);
        $this->db->delete('user');
    }

    function kls() {
        $this->db->order_by("id", "asc");
        $kls = $this->db->get('kelas');
        if ($kls->num_rows > 0) {
            return $kls->result();
        }
    }

    function thn() {
        $this->db->order_by("thn", "asc");
        $th = $this->db->get('tahun');
        if ($th->num_rows > 0) {
            return $th->result();
        }
    }

    function get_privilege() {
        $get = $this->db->get('akses');
        if ($get->num_rows > 0) {
            return $get->result();
        }
    }

    function add_privilege($input) {
        $this->db->insert('akses', $input);
    }

    function del_privilege($id) {
        $this->db->where('id', $id);
        $this->db->delete('akses');
    }

    function get_privilege_id($id) {
        $this->db->where('id', $id);
        $data = $this->db->get('akses');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function upd_privilege($input) {
        $this->db->where('id', $input['id']);
        $this->db->update('akses', $input);
    }

    function slider() {
        $data = $this->db->get('slider');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function get_berita() {
        $data = $this->db->get('news');
        if ($data->num_rows > 0) {
            return $data->num_rows();
        }
    }

    function berita($config) {
        $this->db->order_by('tgl', 'desc');
        $data = $this->db->get('news', $config['per_page'], $config['uri']);
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function berita_id($id) {
        $this->db->where('id', $id['id']);
        $data = $this->db->get('news');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function add_berita($input) {
        $this->db->insert('news', $input);
    }

    function news() {
        $this->db->order_by('id', 'desc');
        $res = $this->db->get('news');
        if ($res->num_rows > 0) {
            return $res->result();
        }
    }

    function get_id_news($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('news');
        return $query->result();
    }

    function upd_news($update) {
        $this->db->where('id', $update['id']);
        $this->db->update('news', $update);
    }

    function del_news($id) {
        $this->db->where('id', $id);
        $this->db->delete('news');
    }

    function berita_detail($id) {
        $this->db->where('id', $id);
        $data = $this->db->get('news');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function daftar_psb($input) {
        $this->db->insert('psb', $input);
    }

    function psb() {
        $this->db->order_by('id');
        $data = $this->db->get('psb');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function get_psb_id($id) {
        $this->db->where('id', $id);
        $data = $this->db->get('psb');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function psb_status($input) {
        $this->db->where('id', $input['id']);
        $this->db->update('psb', $input);
    }

    function profil($id) {
        $this->db->where('id', $id['id']);
        $data = $this->db->get('vuser_det');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function profil_update($id, $input) {
        $this->db->where('id', $id['id']);
        $this->db->update('user', $input);
    }

    function jadwal_mengajar($id) {
        $this->db->order_by('hariId');
        $this->db->order_by('jam_ke');
        $this->db->where('id', $id['id']);
        $data = $this->db->get('vjadwal_mengajar');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function nilai($id) {
        $this->db->where('nip', $id['id']);
        $data = $this->db->get('vnilai');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function get_nilai($id) {
        $this->db->where('nis', $id);
        $data = $this->db->get('vnilai');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function nilai_update($where, $input) {
        $this->db->where($where);
        $this->db->update('mapel_ambil', $input);
    }

    function materi($id) {
        $this->db->where('nip', $id['id']);
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function materi_mapel($nip) {
        $this->db->where('nip', $nip['id']);
        $this->db->group_by('mapel_id');
        $data = $this->db->get('vnilai');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function materi_semester($nip) {
        $this->db->where('nip', $nip['id']);
        $this->db->group_by('semester_id');
        $data = $this->db->get('vnilai');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function materi_tahun($nip) {
        $this->db->where('nip', $nip['id']);
        $this->db->group_by('tahun_id');
        $data = $this->db->get('vnilai');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function materi_upload($input, $data) {
        $in = array(
            'judul' => $input['judul'],
            'mapel_id' => $input['mapel_id'],
            'semester_id' => $input['semester_id'],
            'tahun_id' => $input['tahun_id'],
            'nip' => $input['nip'],
            'file_name' => $data['file_name'],
            'file_type' => $data['file_type'],
            'file_path' => $input['file_path'],
            'file_ext' => $data['file_ext'],
            'file_size' => $data['file_size']
        );
        $this->db->insert('materi', $in);
    }

    function sejarah() {
        $this->db->where('section', 'sejarah');
        $data = $this->db->get('general');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function sejarah_update($input) {
        $this->db->where('section', 'sejarah');
        $this->db->update('general', $input);
    }

    function prasarana() {
        $this->db->where('section', 'prasarana');
        $data = $this->db->get('general');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function prasarana_update($input) {
        $this->db->where('section', 'prasarana');
        $this->db->update('general', $input);
    }

    function visi() {
        $this->db->where('section', 'visi');
        $data = $this->db->get('general');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function visi_update($input) {
        $this->db->where('section', 'visi');
        $this->db->update('general', $input);
    }

}

?>